package com.jbm.enterapplication.activityhome.presenter

import android.content.Context
import com.jbm.enterapplication.InterfaceMa
import com.jbm.enterapplication.activityhome.mode.Open_Mode
import com.jbm.enterapplication.activityhome.view.Open_Door_In
import com.jbm.enterapplication.utlisclass.SaveOpenKeyManage
import com.jbm.onehome.iface.IEGuardKey
import com.jbm.onehome.iface.IEGuardKeyCtrl
import java.util.*

/**
 * Created by 家帮忙 on 2017/9/4.
 */
class Open_Present :Open_Present_In{
    var context:Context?=null
    var opendoor:Open_Door_In?=null
   var openmode:Open_Mode?=null
    private var ArrayListIEKey: ArrayList<IEGuardKey>? = null
    constructor(context: Context?, opendoor: Open_Door_In?) {
        this.context = context
        this.opendoor = opendoor
         openmode= Open_Mode()
    }
    override fun getOpenDoorKey() {
        openmode?.getOpenDoorKey(object :InterfaceMa<IEGuardKeyCtrl>{
            override fun onSuccess(t: IEGuardKeyCtrl, boolean: Boolean) {
                ArrayListIEKey = ArrayList<IEGuardKey>()
                if (t.m_code==200){
                    for (i in 0..t.count - 1) {
                        val keyctrl = t.IndexofList(i)
                        ArrayListIEKey?.add(keyctrl)
                    }
                    //保存用户开门key
                    SaveOpenKeyManage(context!!).setsaveOpenkey(ArrayListIEKey!!)
                }
            }

            override fun setError(err: IEGuardKeyCtrl, boolean: Boolean) {

            }


        })
    }
}